// This cpp file is designed to provide an implementation for
// our character setup window
//
// Created by Christopher Bowlsby
// Last updated on 11/23

#include "createPlayer.h"
#include "ui_createplayer.h"
#include <cstdlib>
#include <ctime>

// constructor
createPlayer::createPlayer(QWidget *parent) :
    QDialog(parent, Qt::WindowMinimizeButtonHint), ui(new Ui::createPlayer) {
    ui->setupUi(this);

}

// destructor
createPlayer::~createPlayer() {
    delete ui;
}


// this function gets the user's desired player name
// player object is only updated when the user hits "Ok"
void createPlayer::on_okButton_clicked() {
    // get character name and set it
    setPlayerName((ui->charName->text()).toStdString());
}


// this function creates the desired class and sets it up for use,
// player object is updated when the user selects their class
void createPlayer::on_classList_currentIndexChanged(int index) {
    // figure out class name and set class picture
    std::string temp;

    if(index == 1) {
        ui->classPic->setStyleSheet("background-image: url(./Data/warrior.png);");
        temp = "Warrior";
    }else if(index == 2) {
        ui->classPic->setStyleSheet("background-image: url(./Data/wizard.png);");
        temp = "Wizard";
    }else if(index == 3) {
        ui->classPic->setStyleSheet("background-image: url(./Data/ranger.png);");
        temp = "Ranger";
    }


    // set player values and update the gui
    setPlayerClass(temp);
    setIndex(index);
    on_regenStats_clicked();
    ui->classPic->update();
}


// this function regenerates stats for a given class when the
// user does not like their starting stats, generated stats are applied
// to the player object each time they are generated
void createPlayer::on_regenStats_clicked() {
    // temporary variables
    PlayerStats myStats;
    std::string temp = this->getPlayerClass();
    int index = this->getIndex();

    // convert class for use in PlayerStats object
    if(temp == "Warrior" && index == 1) {
        myStats = PlayerStats(WARRIOR);
    }else if(temp == "Wizard" && index == 2) {
        myStats = PlayerStats(WIZARD);
    }else if(temp == "Ranger" && index == 3) {
        myStats = PlayerStats(RANGER);
    }

    // set stats
    ui->agility->setNum(myStats.getAgility());
    ui->strength->setNum(myStats.getStrength());
    ui->intelligence->setNum(myStats.getIntelligence());
    ui->concentration->setNum(myStats.getConcentration());

    // update GUI and PlayerStats object
    ui->statsWidget->update();
    setPlayerStats(myStats);
}


// setters and getters
void createPlayer::setPlayerName(std::string name) {
    pname = name;
}
std::string createPlayer::getPlayerName() const {
    return pname;
}
void createPlayer::setPlayerClass(std::string cclass) {
    pclass = cclass;
}
std::string createPlayer::getPlayerClass() const {
    return pclass;
}
void createPlayer::setPlayerStats(PlayerStats temp) {
    pStats = temp;
}
PlayerStats createPlayer::getPlayerStats() const {
    return pStats;
}
void createPlayer::setIndex(int num) {
   ind = num;
}
int createPlayer::getIndex() const {
    return ind;
}
